{include file="public/layout" /}
<body>
  <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
          <div class="layui-col-md12">
            <div class="layui-card">
              <div class="layui-card-body web-system" pad15>
                <div class="layui-form" wid100 lay-filter="">
                  <div class="layui-form-item">
                    <label class="layui-form-label"><b>*</b>模型名称</label>
                    <div class="layui-input-inline">
                     <input type="text" name="ntitle" value="" lay-verify="required" class="layui-input">
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label"><b>*</b>模型标识</label>
                    <div class="layui-input-inline">
                      <input type="text" name="nid" value="" id="nid" lay-verify="required|check_nid" class="layui-input" onkeyup="this.value=this.value.replace(/[^a-z0-9]/g,'');" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^a-z0-9]/g,''));">
                    </div>
                    <div class="layui-form-inline2">
                        与文档的模板相关连，建议由小写字母、数字组成，因为部份Unix系统无法识别中文文件。<br/>
                        列表模板是：lists_模型标识.htm<br/>
                        文档模板是：view_模型标识.htm
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">允许标题重复</label>
                    <div class="layui-input-inline w70">
                        <input type="checkbox" lay-filter="is_repeat_title" lay-skin="switch" lay-text="是|否" checked>
                        <input type="hidden" name="is_repeat_title" value="1" />
                    </div>
                    <div class="layui-input-inline layui-btn-container " style="width: auto;">
                      <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                      <div class="layui-form-inline2 ey_helptips_txt">新增/编辑文档时，是否允许标题的重复</div>
                    </div>
                  </div>
                    <!--<div class="layui-form-item">-->
                        <!--<label class="layui-form-label">关联模型</label>-->
                        <!--<div class="layui-input-inline">-->
                            <!--<select id="join_id" name="join_id">-->
                                <!--<option value=""  >无关联</option>-->
                                <!--{volist name="$list" id="vo"}-->
                                <!--<option value="{$vo.id}" {eq name="$field.join_id" value="$vo.id" } selected {/eq} >{$vo.title}</option>-->
                                <!--{/volist}-->
                            <!--</select>-->
                        <!--</div>-->
                        <!--<div class="layui-input-inline layui-btn-container " style="width: auto;">-->
                            <!--<div class="layui-form-mid layui-word-aux ey_helptips"></div>-->
                            <!--<div class="layui-form-inline2 ey_helptips_txt">关联模型</div>-->
                        <!--</div>-->
                    <!--</div>-->
                    <!--<div class="layui-form-item">-->
                        <!--<label class="layui-form-label">关联经纪人</label>-->
                        <!--<div class="layui-input-inline w70">-->
                            <!--<input type="checkbox" lay-filter="is_join_user" lay-skin="switch" lay-text="是|否" >-->
                            <!--<input type="hidden" name="is_join_user" value="0" />-->
                        <!--</div>-->
                        <!--<div class="layui-input-inline layui-btn-container " style="width: auto;">-->
                            <!--<div class="layui-form-mid layui-word-aux ey_helptips"></div>-->
                            <!--<div class="layui-form-inline2 ey_helptips_txt">新增/编辑文档时，是否允许关联经纪人</div>-->
                        <!--</div>-->
                    <!--</div>-->
                  <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
                    </div>
                  </div>
              </div>
            </div>
          </div>
        </div>
  </div>

  <script>
  layui.config({
    base: '__SKIN__/' //静态资源所在路径
    ,version: '{$version}'
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set'], function(){
    var $ = layui.$
    ,layer = layui.layer
    ,form = layui.form;

    var parentObj = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    
    form.verify({
      check_nid: function(value, item){ //value：表单的值、item：表单的DOM对象
        if(value == ''){
            return '模型标识不能为空！';
        } else {
            var reg = /^([a-z]+)([a-z0-9]*)$/i;
            if(!reg.test(value)){
                return '模型标识必须以小写字母开头！';
            }
        }
      }
    }); 

    // 监听开关
    form.on('switch', function(data){
      var elemId = data.elem.attributes['lay-filter']['nodeValue'];
      if (data.elem.checked) {
        this.value = 1;
      } else {
        this.value = 0;
      }
      $("input[name='"+elemId+"']").val(this.value);
    });

    //监听提交
    form.on('submit(formSubmit)', function(data){
        var load = layer_loading();
        data.field._ajax = 1;
        $.ajax({
            type : 'post',
            url : "{:url('Channeltype/add')}",
            data : data.field,
            dataType : 'json',
            success : function(res){
                layer.close(load); //关闭loading
                if(res.code == 1){
                    layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                        parent.gourl(res.url);
                    });
                }else{
                    parent.showErrorMsg(res.msg);
                }
            },
            error: function(e){
                layer.close(load); //关闭loading
                showErrorAlert();
            }
        });
        return false;
    });

  });

  </script>
{include file="public/footer" /}